﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_CancelPostil]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_CancelPostil];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_CancelPostil]
    @DocID int
AS

DELETE FROM uds_flow_postil 
    WHERE Doc_ID =@DocID 
      and
        postil_date = 
                (SELECT TOP 1 postil_date 
                    FROM  uds_flow_postil 
                    WHERE Doc_ID =@DocID 
                    ORDER BY postil_date DESC
                )